//
//  AONavigationController.swift
//  weibo_zha
//
//  Created by _zha on 16/10/23.
//  Copyright © 2016年 渣. All rights reserved.
//

import UIKit

class AONavigationController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义导航栏按钮滑动bug解决
        interactivePopGestureRecognizer?.delegate = self
    }
    
    //点击事件
    @objc private func backClick() {
        popViewController(animated: true)
    }
    
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        var title: String
        // 由于消息 发现 我 均有返回按钮 = bug
        if childViewControllers.count > 0 {
            title = "返回"
            //第一次push
            if childViewControllers.count == 1 {
                //首页的title
                title = childViewControllers.first?.title ?? ""
            }
            //导航左侧按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(setHighlightedImgName: "navigationbar_back_withtext", title: title, target:  self, action: #selector(backClick))
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    //
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        //不能在滑动了
        return childViewControllers.count != 1
    }
}
